package com.woniu.web.service.impl;

import com.woniu.common.entity.TbJpBedinfo;
import com.woniu.common.entity.TbJpBedinfoExample;
import com.woniu.resultSet.Result;
import com.woniu.web.controller.bedinfo.BedinfoExample;
import com.woniu.web.mapper.TbJpBedinfoDao;
import com.woniu.web.service.TbJpBedInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author jiaoxiuxiu
 * @date 2020/9/24 14:31
 */
@Service
@Transactional
public class TbJpBedInfoServiceImpl implements TbJpBedInfoService {
    @Resource
    TbJpBedinfoDao tbJpBedinfoDao;


    @Override
    public Integer deleteBed(Long id) {
        return tbJpBedinfoDao.deleteByPrimaryKey(id);

    }

    @Override
    public Integer DeleteByArray(Long[] ids) {
        TbJpBedinfoExample example=new TbJpBedinfoExample();
        example.createCriteria().andIdIn(Arrays.asList(ids));
        return tbJpBedinfoDao.deleteByExample(example);
    }

    @Override
    public Integer updateBgrStatus(Long id) {
        TbJpBedinfo tbJpBedinfo=new TbJpBedinfo();
        tbJpBedinfo.setId(id);
        tbJpBedinfo.setBgrStatus(2);
        return tbJpBedinfoDao.updateByPrimaryKeySelective(tbJpBedinfo);
    }

    @Override
    public List findBybedinfoExample(BedinfoExample bedinfoExample) {
        TbJpBedinfoExample example=new TbJpBedinfoExample();
        //判断查询条件床位
        if(bedinfoExample.getId()!=null){
            example.createCriteria().andIdEqualTo(bedinfoExample.getId());
        }
        //判断查询条件医院id
        if(bedinfoExample.getHospitalid()!=null){
            example.createCriteria().andHospitalidEqualTo(bedinfoExample.getHospitalid());
        }
        //判断查询条件医院科室id
        if(bedinfoExample.getHospitalKeshi()!=null){
            example.createCriteria().andHospitalKeshiEqualTo(bedinfoExample.getHospitalKeshi());
        }
        //判断查询条件医院科室id
        if(bedinfoExample.getBgrStatus()!=null){
            example.createCriteria().andBgrStatusEqualTo(bedinfoExample.getBgrStatus());
        }
        //判断查询条件电池电量
        if(bedinfoExample.getBatteryLevel()=="21"){
            example.createCriteria().andBatteryLevelGreaterThan("20");
        }else if(bedinfoExample.getBatteryLevel()=="20"){
            example.createCriteria().andBatteryLevelLessThan("20");
        }
        //判断查询条件时间区间
        if(bedinfoExample.getTimeExample().length==2){
            example.createCriteria().andAddTimeBetween(bedinfoExample.getTimeExample()[0],bedinfoExample.getTimeExample()[1]);
        }
        //判断查询条件床位审核状态
        if(bedinfoExample.getStatus()!=null){
            example.createCriteria().andStatusEqualTo(bedinfoExample.getStatus());
        }
        return tbJpBedinfoDao.selectByExample(example);
    }

    @Override
    public Integer updateStatus(Long id) {
        TbJpBedinfo tbJpBedinfo=new TbJpBedinfo();
        tbJpBedinfo.setId(id);
        tbJpBedinfo.setRemark("2");
        return tbJpBedinfoDao.updateByPrimaryKeySelective(tbJpBedinfo);
    }

    @Override
    public Integer bootupStatus(Long id) {
        TbJpBedinfo tbJpBedinfo=new TbJpBedinfo();
        tbJpBedinfo.setId(id);
        tbJpBedinfo.setRemark("1");
        return tbJpBedinfoDao.updateByPrimaryKeySelective(tbJpBedinfo);
    }

    @Override
    public TbJpBedinfo findOne(Long id) {
       return tbJpBedinfoDao.selectByPrimaryKey(id);
    }
}
